#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
void ChildProcess(void);
void ParentProcess(void);
int pid;
int i;
int parent_pid;
int child_pid;
int the_pid;
int main(void)
{
parent_pid=getpid();
child_pid=fork(); /*Returns child_pid to parent*/
if (getpid()==parent_pid) {
printf("\nIn the parent: parent %d - child %d\n",parent_pid,child_pid);
} else {
printf("\nBefore child getting its getpid(): parent %d - child %d\n",parent_pid,child_pid);
child_pid=getpid();
printf("After child getting its getpid(): parent %d - child %d\n\n",parent_pid,child_pid);
}
if (getpid()==child_pid) {
ChildProcess();
} else {
ParentProcess();
}
return 0;
}
void ChildProcess(void)
{
while (i<6) {
printf ("The child with pid %d is doing some work and the present value of i=%d\n", getpid(),i);
i++;
sleep(3);
}
}
void ParentProcess(void)
{
while (i<6) {
printf ("The parent with pid %d is doing some work and the present value of i=%d\n", getpid(),i);
i++;
sleep(1);
}
}

I had to stop the child in the command window.